from django.contrib import admin

from app.admin import FormBaseConfig

from . import models
from .resources import BookAuthorResource, BookChatpterResource, BookResource, ListenBookResource

# Register your models here.


@admin.register(models.Book)
class BookAdmin(FormBaseConfig):
    resource_class = BookResource  # 👈 加这一行
    # autocomplete_fields = ['author_ids']
    list_display = ("id", "name", "author_ids", "price",
                    "publish", "publish_date", "active")
    list_filter = ("author_ids", "tags", "publish", "word_count")
    search_fields = ("name", "author_ids", "tags", "publish")
    list_display_links = ("id", "name", "author_ids", "price", "publish")
    # list_editable = ("price", "author")
    list_per_page = 10

    # class Media:
    #     css = {
    #         "all": ("css/admin_custom.css",)  # 注意路径是相对于 STATIC_URL
    #     }


@admin.register(models.BookChatpter)
class BookChatpterAdmin(FormBaseConfig):
    resource_class = BookChatpterResource  # 👈 加这一行
    list_display = ("id", "book_id", "chapter_index", "chapter_type",
                    "chapter_topic", "key_points", "active")
    list_filter = ("chapter_index", "created_at", "updated_at")
    search_fields = ("book_id", "chapter_index",
                     "chapter_topic", "key_points", "chapter_type")
    # list_editable = ("name", "content")
    list_display_links = ("id", "book_id", "chapter_index",
                          "chapter_type", "chapter_topic", "key_points")
    list_per_page = 10

    # class Media:
    #     css = {
    #         "all": ("css/admin_pro.css",)  # 注意路径是相对于 STATIC_URL
    #     }


@admin.register(models.BookAuthor)
class BookAuthorAdmin(FormBaseConfig):
    resource_class = BookAuthorResource  # 👈 加这一行
    list_display = ("id", "name", "introduction",
                    "cover_url", "active")
    list_filter = ("name",)
    search_fields = ("name", "introduction", "cover_url", "books__name")
    # list_editable = ("name", "content")
    list_display_links = ("id", "name", "introduction", "cover_url")
    list_per_page = 10


@admin.register(models.ListenBook)
class ListenBookAdmin(FormBaseConfig):
    resource_class = ListenBookResource  # 👈 加这一行
    # autocomplete_fields = ['book_id', 'listener']
    list_display = ("id", "book_id", "listener_id", "title", "introduction",
                    "listen_count", "listen_time", "publish_date", "active")
    # list_filter = ( "book_id", "listen_book_id", "user_id", "note_id")
    list_display_links = ("id", "book_id", "listener_id", "title", "introduction",
                          "listen_count", "listen_time", "publish_date")
    search_fields = ("book__name", "listener__name", "title", "introduction",
                     "listen_count", "listen_time", "publish_date")


@admin.register(models.ListBookNote)
class ListBookNoteAdmin(FormBaseConfig):
    # autocomplete_fields = ['book_id', 'listen_book_id']
    list_display = ("id", "book_id", "listen_book_id", "note", "like_count",
                    "comment_count", "collect_count", "share_count", "read_count", "active")
    # list_filter = ( "book_id", "listen_book_id", "user_id", "note_id")
    search_fields = ("book_id", "listen_book_id", "note", "like_count",
                     "comment_count", "collect_count", "share_count", "read_count", "comments")
    # list_editable = ("name", "content")
    list_display_links = ("id", "book_id", "listen_book_id", "note",
                          "like_count", "comment_count", "collect_count", "share_count", "read_count")
    list_per_page = 10


@admin.register(models.BookNote)
class BookNoteAdmin(FormBaseConfig):
    # autocomplete_fields = ['book_id']
    list_display = ("id", "book_id", "chapter_index", "chapter_type", "note", "like_count",
                    "comment_count", "collect_count", "share_count", "read_count", "active")
    # list_filter = ( "book_id", "listen_book_id", "user_id", "note_id")
    search_fields = ("book__name", "note", "like_count", "comment_count",
                     "collect_count", "share_count", "read_count", "comments")
    # list_editable = ("name", "content")
    list_display_links = ("id", "book_id", "chapter_index", "chapter_type", "note", "like_count",
                          "comment_count", "collect_count", "share_count", "read_count")
    list_per_page = 10


@admin.register(models.ListenBookAuthor)
class ListenBookAuthorAdmin(FormBaseConfig):
    list_display = ("id", "name",
                    "introduction", "write_book_ids", "active")
    list_filter = ("active",)
    search_fields = ("name", "introduction", "write_book_ids")
    # list_editable = ("name", "content")
    list_display_links = ("id", "name",
                          "introduction", "write_book_ids")
    list_per_page = 10
